import {
  appGetStorage,
  appSetStorage,
  appRemoveStorage,
} from "@/utils/storage";
import store from "@/store";

const TokenKey = "PUB_MINI_APP_CATCH_TOKEN";
export function getToken() {
  const store_token = store?.state["sp-common/auth"]?.app_token;
  return store_token || appGetStorage(TokenKey);
}

export function setToken(token) {
  return new Promise((resolve, rejected) => {
    appSetStorage(TokenKey, token);
    const isHas = !!getToken(TokenKey);
    if (isHas) {
      resolve();
    } else {
      rejected();
    }
  });
}

export function removeToken() {
  return appRemoveStorage(TokenKey);
}
